#!/bin/bash
# params eg: eppv5 v5.12.2 regxxx regxxx
n=0
product=$1
version=$2
for i in "$@"
do
	if [ $n -ge 2 ]; then
		a=`echo "${i}"|awk -F / '{print $1;}'`
		arm=`echo "${i}"|awk -F / '{print $2;}'`
		if [[ '${arm}' =~ 'arm64' ]]; then
			b="${product}-arm64"
		else
			b="${product}"
		fi
		c=`echo "${i}"|awk -F / '{print $3;}'|awk -F : '{print $1;}'`
		
		d="${a}/${b}/${c}:${version}"
		
		echo "====docker pull ${i}"
		docker pull ${i}
		echo "====docker tag ${i} ${d}"
		docker tag ${i} ${d}
		echo "====docker push ${d}"
		docker push ${d}
		echo "====docker rmi ${d}"
		docker rmi ${d}
		echo "====docker rmi ${i}"
		docker rmi ${i}
	fi
	n=$((n+1))
done
